package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.DestinationComment;
import cn.wolfcode.luowowo.article.mapper.DestinationCommentMapper;
import cn.wolfcode.luowowo.article.query.DestinationCommentQuery;
import cn.wolfcode.luowowo.article.service.IDestinationCommentService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class DestinationCommentServiceImpl implements IDestinationCommentService {
    @Autowired
    private DestinationCommentMapper destinationCommentMapper;

    @Override
    public PageInfo query(DestinationCommentQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        return new PageInfo(destinationCommentMapper.selectForList(qo));
    }

    @Override
    public void saveOrUpdate(DestinationComment destinationComment) {
        if(destinationComment.getId() == null){
            destinationCommentMapper.insert(destinationComment);
        }else{
            destinationCommentMapper.updateByPrimaryKey(destinationComment);
        }
    }

    @Override
    public List<DestinationComment> list() {
        return destinationCommentMapper.selectAll();
    }
}
